//
//  leftNav.m
//  Candy
//
//  Created by QUAQUA on 2018/3/18.
//  Copyright © 2018年 庄文盛 All rights reserved.
//
#import "leftNav.h"
#import "YSHYSlideViewController.h"
#import "News.h"
#import "myListController.h"
#import "Header.h"
#import "UserModel.h"
#import "PersonDesignViewController.h"
#import "SWFormCommonController.h"

@interface leftNav ()
@property (weak, nonatomic) IBOutlet UIImageView *home;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *name2;
@property (weak, nonatomic) IBOutlet UILabel *adress;
@property (weak, nonatomic) IBOutlet UILabel *news;
@property (weak, nonatomic) IBOutlet UILabel *history;
@property (weak, nonatomic) IBOutlet UILabel *collection;
@property (weak, nonatomic) IBOutlet UILabel *setting;
@property (weak, nonatomic) IBOutlet UILabel *ban;
@property (weak, nonatomic) IBOutlet UILabel *exit;
@property (weak, nonatomic) IBOutlet UILabel *advice;
@property (nonatomic, strong) UserModel *model;

@end

@implementation leftNav

- (UserModel *)model {
    if (!_model) {
        _model = [UserModel new];
    }
    return _model;
}

- (void)viewWillAppear:(BOOL)animated {
  
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    SWFormCommonController *vc = [SWFormCommonController new];
//    vc.coinDelete = self;
    [SVProgressHUD showWithStatus:@"loading"];
    AFHTTPSessionManager* session=[AFHTTPSessionManager manager];
    session.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSDictionary *pra = @{@"id":[[NSUserDefaults standardUserDefaults]stringForKey:USERID]};
    [session GET:@"http://127.0.0.1:3000/user" parameters:pra progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"下载成功");
        NSString *source = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        self.model = [UserModel mj_objectWithKeyValues:source];
        self.name.text = self.model.name;
        self.name2.text = self.model.school;
        self.adress.text = [NSString stringWithFormat:@"葡萄：%@",self.model.coin];
        NSLog(@"%@",self.adress.text);
        [[NSUserDefaults standardUserDefaults]setValue:_model.school forKey:SCHOOL];
        [[NSUserDefaults standardUserDefaults]setValue:_model.coin forKey:COIN];
        [[NSUserDefaults standardUserDefaults]setValue:_model.name forKey:USERNAME];
        [[NSUserDefaults standardUserDefaults]setValue:_model.email forKey:EMAIL];
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"下载失败");
    }];
    
    self.coverView = [[UIView alloc]initWithFrame:CGRectMake(0,0, 0,0 )];
    [self.coverView setBackgroundColor:[UIColor blackColor]];
    self.coverView.alpha = 0;
    [self.view addSubview:self.coverView];
    self.coverView.hidden=YES;
    UIImage *backGround=[UIImage imageNamed:@""];
    
    UIImageView *img=[[UIImageView alloc]initWithImage:backGround];
    [self.view addSubview:img];
    _home.alpha=1.0;
    [self.view addSubview:_home];
    [self.view addSubview:_name];
    [self.view addSubview:_name2];
    [self.view addSubview:_news];
    [self.view addSubview:_adress];
    [self.view addSubview:_advice];
    [self.view addSubview:_history];
    [self.view addSubview:_exit];
    [self.view addSubview:_setting];
    [self.view addSubview:_collection];
    [self.view addSubview:_ban];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ChargeEye)];
   
    [_news setUserInteractionEnabled:YES];
   
    tap1.numberOfTapsRequired = 1;
    tap1.numberOfTouchesRequired = 1;
    
    [_news addGestureRecognizer:tap1];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toMylistController)];
    
    [_history setUserInteractionEnabled:YES];
    
    tap2.numberOfTapsRequired = 1;
    tap2.numberOfTouchesRequired = 1;
    
    [_history addGestureRecognizer:tap2];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toCollectionView)];
    
    [_collection setUserInteractionEnabled:YES];
    
    tap3.numberOfTapsRequired = 1;
    tap3.numberOfTouchesRequired = 1;
    
    [_collection addGestureRecognizer:tap3];
    
    
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toPerson)];
    
    [_name setUserInteractionEnabled:YES];
    
    tap4.numberOfTapsRequired = 1;
    tap4.numberOfTouchesRequired = 1;
    
    [_name addGestureRecognizer:tap4];
    // Do any additional setup after loading the view from its nib.
}

- (void)toPerson {
    PersonDesignViewController *vc = [PersonDesignViewController new];
    vc.title = @"个人资料";
    vc.model = self.model;
    [[YSHYSlideViewController shareInstance] setMainViewController:vc];
    [[YSHYSlideViewController shareInstance] yyy];
    [[YSHYSlideViewController shareInstance] CloseMenu];
}

- (void)toMylistController {
    myListController *collection = [[myListController alloc]init];
    collection.title = @"我的订单";
    collection.listOrCollection = 1;
    [[YSHYSlideViewController shareInstance] setMainViewController:collection];
    [[YSHYSlideViewController shareInstance] yyy];
    [[YSHYSlideViewController shareInstance] CloseMenu];
}

- (void)toCollectionView {
    myListController *collection = [[myListController alloc]init];
    collection.title = @"个人收藏";
    collection.listOrCollection = 2;
    [[YSHYSlideViewController shareInstance] setMainViewController:collection];
    [[YSHYSlideViewController shareInstance] yyy];
    [[YSHYSlideViewController shareInstance] CloseMenu];
}

-(void)ChargeEye{
    [[YSHYSlideViewController shareInstance] setMainViewController:[[News alloc]init]];
    [[YSHYSlideViewController shareInstance] yyy];
    [[YSHYSlideViewController shareInstance] CloseMenu];
  
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//- (void)sendValue:(NSString *)value
//{
//    self.adress.text = [NSString stringWithFormat:@"印币：%@",value];
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
